
package example

import (
	"context"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/example"
    exampleReq "github.com/flipped-aurora/gin-vue-admin/server/model/example/request"
)

type BwAssessmentTasksService struct {}
// CreateBwAssessmentTasks 创建考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService) CreateBwAssessmentTasks(ctx context.Context, bwAssessmentTasks *example.BwAssessmentTasks) (err error) {
	err = global.GVA_DB.Create(bwAssessmentTasks).Error
	return err
}

// DeleteBwAssessmentTasks 删除考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService)DeleteBwAssessmentTasks(ctx context.Context, id string) (err error) {
	err = global.GVA_DB.Delete(&example.BwAssessmentTasks{},"id = ?",id).Error
	return err
}

// DeleteBwAssessmentTasksByIds 批量删除考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService)DeleteBwAssessmentTasksByIds(ctx context.Context, ids []string) (err error) {
	err = global.GVA_DB.Delete(&[]example.BwAssessmentTasks{},"id in ?",ids).Error
	return err
}

// UpdateBwAssessmentTasks 更新考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService)UpdateBwAssessmentTasks(ctx context.Context, bwAssessmentTasks example.BwAssessmentTasks) (err error) {
	err = global.GVA_DB.Model(&example.BwAssessmentTasks{}).Where("id = ?",bwAssessmentTasks.Id).Updates(&bwAssessmentTasks).Error
	return err
}

// GetBwAssessmentTasks 根据id获取考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService)GetBwAssessmentTasks(ctx context.Context, id string) (bwAssessmentTasks example.BwAssessmentTasks, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&bwAssessmentTasks).Error
	return
}
// GetBwAssessmentTasksInfoList 分页获取考核任务记录
// Author [yourname](https://github.com/yourname)
func (bwAssessmentTasksService *BwAssessmentTasksService)GetBwAssessmentTasksInfoList(ctx context.Context, info exampleReq.BwAssessmentTasksSearch) (list []example.BwAssessmentTasks, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&example.BwAssessmentTasks{})
    var bwAssessmentTaskss []example.BwAssessmentTasks
    // 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	if err!=nil {
    	return
    }

	if limit != 0 {
       db = db.Limit(limit).Offset(offset)
    }

	err = db.Find(&bwAssessmentTaskss).Error
	return  bwAssessmentTaskss, total, err
}
func (bwAssessmentTasksService *BwAssessmentTasksService)GetBwAssessmentTasksPublic(ctx context.Context) {
    // 此方法为获取数据源定义的数据
    // 请自行实现
}
